package com.hopes.bizz.risk.gis.constant;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;

import java.util.Date;

public enum RiskStatisticsCycleEnum {
    week,
    month,
    year,
    ;

    public static Date getBeginDate(RiskStatisticsCycleEnum cycle) {
        Date endDate = DateUtil.beginOfDay(new Date());
        if (week.equals(cycle)) {
            return DateUtil.offsetWeek(endDate, -1);
        } else if (month.equals(cycle)) {
            return DateUtil.offsetMonth(endDate, -1);
        } else if (year.equals(cycle)) {
            return DateUtil.offsetMonth(endDate, -12);
        }
        return null;
    }

    public static String getDateFormat(RiskStatisticsCycleEnum cycle, Date date) {
        switch (cycle) {
            case week:
            case month:
                return DateUtil.formatDate(date);
            case year:
                return DateUtil.format(date, "yyyy年MM月");
            default:
                return null;
        }
    }

    public static DateField getDateField(RiskStatisticsCycleEnum cycle) {
        switch (cycle) {
            case week:
            case month:
                return DateField.DAY_OF_YEAR;
            case year:
                return DateField.MONTH;
            default:
                return null;
        }
    }
}
